package com.moly.websocketone.configuration.websocket;

import com.moly.websocketone.configuration.websocket.handler.ListeningWebsocket;
import com.moly.websocketone.configuration.websocket.Interceptor.WebsocketHandShakeIntecepter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @Description: 配置普通的springboot 改进过的 websocket
 * @Author: m01
 * @Date: created at  2018/11/11  19:52
 * @Modified By:
 */
@Configuration
@EnableWebSocket
public class WebSocketConfigWithSpring implements WebSocketConfigurer {
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(new ListeningWebsocket(), "/originalendpointupdate")
                .addInterceptors(websocketHandShakeIntecepter())
                .setAllowedOrigins("*")
                .withSockJS();

        webSocketHandlerRegistry.addHandler(new ListeningWebsocket(), "/originalendpointupdate")
                .addInterceptors(websocketHandShakeIntecepter())
                .setAllowedOrigins("*");


    }

    @Bean
    public WebsocketHandShakeIntecepter websocketHandShakeIntecepter(){
        return new WebsocketHandShakeIntecepter();
    }

}
